/*
 * Powered By 
 * Since 2010 - 2016
 */

package com.rf.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rf.sys.utils.PageUtils;
import com.rf.sys.utils.ConfigUtils;
import com.rf.sys.utils.UuidUtil;
import com.rf.sys.dao.UserLoginLogMapper;
import com.rf.sys.dao.SqlAdapterMapper;
import com.rf.sys.model.UserLoginLog;
import com.rf.sys.model.UserLoginLogExample;
import com.rf.sys.service.UserLoginLogService;

@Service("userLoginLogService")
public class UserLoginLogServiceImpl implements UserLoginLogService {
	
	@Autowired
   	private SqlAdapterMapper sqlAdapterMapper;//注入dao
   	@Autowired
   	private UserLoginLogMapper userLoginLogMapper;//注入dao

   	/**
	 * 根据id获取数据
	 * @param userLoginLogId
	 * @return UserLoginLog
	 */
   	@Override
	public UserLoginLog getUserLoginLogByID(String id) throws Exception{
		// TODO Auto-generated method stub
		return userLoginLogMapper.selectByPrimaryKey(id);
	}
	
	/**
	 * 根据UserLoginLog获取数据
	 * @param UserLoginLog
	 * @return List<UserLoginLog>
	 */
	@Override
	public List<UserLoginLog> getUserLoginLog(UserLoginLog userLoginLog) throws Exception{
		// TODO Auto-generated method stub
		UserLoginLogExample example = new UserLoginLogExample();
		com.rf.sys.model.UserLoginLogExample.Criteria criteria= example.createCriteria();
		
		//criteria.andStateNotEqualTo(ConfigUtils.DELSTATE);//不查询已删除的
		List<UserLoginLog> list = userLoginLogMapper.selectByExample(example);
		return list;
	}
	
	/**
	 * 获取所有数据
	 * @param 
	 * @return List<UserLoginLog>
	 */
	@Override
	public List<UserLoginLog> getUserLoginLog() throws Exception{
		// TODO Auto-generated method stub
		UserLoginLogExample example = new UserLoginLogExample();
		com.rf.sys.model.UserLoginLogExample.Criteria criteria= example.createCriteria();
		
		//criteria.andStateNotEqualTo(ConfigUtils.DELSTATE);//不查询已删除的
		return userLoginLogMapper.selectByExample(example);
	}
   	
	/**
	 * 保存信息
	 * @param UserLoginLog
	 * @return
	 */
	@Override
	public void addUserLoginLog(UserLoginLog userLoginLog) throws Exception{
		// TODO Auto-generated method stub
		userLoginLog.setId(UuidUtil.get32UUID());
		userLoginLogMapper.insert(userLoginLog);
	}

	/**
	 * 修改数据
	 * @param UserLoginLog
	 * @param
	 */
	@Override
	public void updateUserLoginLog(UserLoginLog userLoginLog) throws Exception{
		// TODO Auto-generated method stub
		userLoginLogMapper.updateByPrimaryKeySelective(userLoginLog);
	}
	
	/**
	 * 删除数据
	 * @param userLoginLogId
	 * @param
	 */
	@Override
	public void deleteUserLoginLog(String id) throws Exception{
		// TODO Auto-generated method stub
		userLoginLogMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 获取数据分页
	 * @param UserLoginLog
	 * @param pageUtils
	 * @return Map
	 */
	@Override
	public Map getUserLoginLogPage(UserLoginLog userLoginLog,PageUtils pageUtils) throws Exception{
		UserLoginLogExample example = new UserLoginLogExample();
		com.rf.sys.model.UserLoginLogExample.Criteria criteria= example.createCriteria();
		
		//获取第offset页，每页共limit条内容，默认查询总数count
		Page p = PageHelper.startPage(pageUtils.getPage(), pageUtils.getRows());
		//下一条执行语句，即为要被转换的语句
		List<UserLoginLog> list = userLoginLogMapper.selectByExample(example);
		Map dateMap = new HashMap();
	    dateMap.put("total", p.getTotal());
	    dateMap.put("rows", list);
		return dateMap;
	}
}

